﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;
using DeviceManagementIT.DevicesManager.Unit;

namespace DeviceManagementIT.DevicesManager.DevicesManagement
{
    public partial class frmComponents : DevExpress.XtraEditors.XtraForm
    {
        PHUTUNG component;
        ComponenetBllOperation componentbll = new ComponenetBllOperation();
        public frmComponents()
        {
            InitializeComponent();
        }

        private void frmComponents_Load(object sender, EventArgs e)
        {
            UnitDbOperation m_UnitDbOperation = new UnitDbOperation();
            cbbDonvitinh.Properties.DataSource = m_UnitDbOperation.GetRecord(new DONVITINH());
            cbbDonvitinh.Properties.DisplayMember = "DVTIT";
            cbbDonvitinh.Properties.ValueMember = "DVTIT";

            GGropDbOperation m_GGropDbOperation = new GGropDbOperation();
            txtLoaiThietBi.Properties.DataSource = m_GGropDbOperation.GetRecord(new LOAITHIETBI());
            txtLoaiThietBi.Properties.DisplayMember = "LoaiTBID";
            txtLoaiThietBi.Properties.ValueMember = "LoaiTBID";

            CountryDbOperation m_CountryDbOperation = new CountryDbOperation();
            cbbNuocSX.Properties.DataSource = m_CountryDbOperation.GetRecord(new NUOC());
            cbbNuocSX.Properties.DisplayMember = "NuocID";
            cbbNuocSX.Properties.ValueMember = "NuocID";

            DeviceDbOperation m_DeviceDbOperation = new DeviceDbOperation();
            lookUpEditThietBi.Properties.DataSource = m_DeviceDbOperation.GetRecord(new THIETBI());
            lookUpEditThietBi.Properties.DisplayMember = "TenThietBi";
            lookUpEditThietBi.Properties.ValueMember = "ThietBiID";
        }

        private void btnSaveLK_Click(object sender, EventArgs e)
        {
            component = new PHUTUNG();
            LOAITHIETBI m_loaithietbi = new LOAITHIETBI();

            component.MaPhuTung = txtMaPhuTung.EditValue.ToString();
            component.TenPhuTung = txtTenPhuTung.EditValue.ToString();
            component.SoHieu = txtSoHieu.EditValue.ToString();
            component.LoaiTBID = m_loaithietbi.LoaiTBID;
            component.DVTID = int.Parse(cbbDonvitinh.EditValue.ToString());
            component.HanBaoHanh = short.Parse(cbbNamSX.EditValue.ToString());
            component.NuocSX = int.Parse(cbbNuocSX.EditValue.ToString());
            component.ThongSoKT = mmeTSKT.EditValue.ToString();
            component.MoTaThem = mmeMoTa.EditValue.ToString();
            //component.HinhAnh = pictureEdit;
            string message = componentbll.SaveRecord(component);
            MessageBox.Show(message, "Message");
        }

        private void simpleButton5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void sbtnLoaithietbi_Click(object sender, EventArgs e)
        {
            frmGGroupDevice m_loaithietbi = new frmGGroupDevice();
            m_loaithietbi.Show();
        }

        private void btnDonvitinh_Click(object sender, EventArgs e)
        {
            frmAddUnit m_themdvt = new frmAddUnit();
            m_themdvt.Show();
        }

        private void btnNuocSX_Click(object sender, EventArgs e)
        {
            
        }
    }
}